function Shape(name) {
    this.name = name;
}
Shape.prototype.calculate = function() {
    console.log('计算' + this.name + '的面积')
}
let s = new Shape('长方形');
s.calculate(); // 输出: 计算长方形的面积
let x = new Shape('梯形');
x.calculate(); // 输出: 计算梯形的面积

/****************************************************** */
function Trapezoid(top, bottom, height) {
    this.top = top;
    this.bottom = bottom;
    this.height = height;
}
Trapezoid.prototype = new Shape('梯形');
Trapezoid.prototype.constructor = Trapezoid;
Trapezoid.prototype.toString = function() {
    return this.name + '上底边长' + this.top + ',' + '下底边长' + this.bottom + ',' + '高' + this.height;
}
Trapezoid.prototype.calculate = function() {
    return (this.top + this.bottom) * this.height / 2;
}
let t1 = new Trapezoid(20, 30, 15); // 上底边、下底边、高 
let s1 = t1.toString();
let x1 = t1.calculate();
console.log(s1); // 梯形上底边长20，下底边长30，高15 
console.log('梯形面积为:', x1); // 梯形面积为: 375
/****************************************************** */

function Triangle(a, b, c) {
    let a1 = a;
    let b1 = b;
    let c1 = c;
    if (a1 + b1 <= c1 || a1 + c1 <= b1 || b1 + c1 <= a1) {
        let ex = new Error('不能组成三角形');
        throw ex;
    }
    this.first = a;
    this.second = b;
    this.third = c;
}
Triangle.prototype = new Shape('三角形');
Triangle.prototype.constructor = Triangle;
Triangle.prototype.toString = function() {
    return this.name + '三边长分别为:' + this.first + '、' + this.second + '、' + this.third;
}
Triangle.prototype.calculate = function() {
    let p = (this.first + this.second + this.third) / 2
    return Math.sqrt(p * (p - this.first) * (p - this.second) * (p - this.third));
}
let t2 = new Triangle(30, 40, 50);
let s2 = t2.toString();
let x2 = t2.calculate();
console.log(s2); // 三角形三边长分别为: 30 、40 、50 
console.log('三角形面积为:', x2); // 三角形面积为: 600